package com.its.util;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 朱厚强
 * @version 1.0
 * @classname RedisUtil
 * 这是一个redis工具类
 */
@Component
@Slf4j
public  class  RedisUtil {
    @Autowired
    private RedisTemplate redisTemplate;
    /**
     * 根据键去获取redis中的数据
     * @param key 键
     * @return
     */
    public List<String> getAreaForRedis(String key) {
        if (key != null){
            List redisList = redisTemplate.opsForHash().values("region:" + key);
            return redisList;
        }else {
            log.error("传入的key为空");
            System.out.println("传入的key为空");
            return null;
        }
    }
}
